var Common = {
	pa: {
		// AJAX请求URL前缀
		_URL_PREFIX: 'http://www.tulaoda.top/apis/NetDianCan/',
		_AJAX_JSON_ERR: {
			code: 999,
		}
	},
	fn: {
		/**
		 * 获取URL参数
		 * name @String 参数名称
		 */
		getUrlParam: function(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if(r != null) {
				return decodeURI(r[2]);
			} else {
				return null;
			}
		}
	}
}

var Model = {
	_URL_P: Common.pa._URL_PREFIX,
	_RESULT: "",
	menu: {
		getType: function(p) {
			$.ajax({
				url: Model._URL_P + "/menu/getType",
				type: "get",
				data: {},
				dataType: "json",
				async: false,
				success: function(result) {
					Model._RESULT = result;
				},
				error: function() {
					Model._RESULT = Common.pa._AJAX_JSON_ERR;
				}
			});
			return Model._RESULT;

		},

		getMenu: function(p) {
			$.ajax({
				url: Model._URL_P + "/menu/getMenuByType",
				type: "get",
				data: {},
				dataType: "json",
				async: false,
				success: function(result) {
					Model._RESULT = result;
				},
				error: function() {
					Model._RESULT = Common.pa._AJAX_JSON_ERR;
				}
			});
			return Model._RESULT;

		},
		addOrder: function(p) {
			var params = {
				tableId: "",
				menuIds: "",
				counts: "",
			};
			for(var i in p) {
				params[i] = p[i];
			}
			$.ajax({
				url: Model._URL_P + "/order/addOrder",
				type: "post",
				data: {
					tableId: params.tableId,
					menuIds: params.menuIds,
					counts: params.counts,
				},
				dataType: "json",
				async: false,
				success: function(result) {
					Model._RESULT = result;
				},
				error: function() {
					Model._RESULT = Common.pa._AJAX_JSON_ERR;
				}
			});
			return Model._RESULT;

		},
		getGoodById: function(p) {
			var params = {
				id: "",
			};
			for(var i in p) {
				params[i] = p[i];
			}
			$.ajax({
				url: Model._URL_P + "menu/getGoodById?=3",
				type: "get",
				data: {
					id: params.id
				},
				dataType: "json",
				async: false,
				success: function(result) {
					Model._RESULT = result;
				},
				error: function() {
					Model._RESULT = Common.pa._AJAX_JSON_ERR;
				}
			});
			return Model._RESULT;

		},
		findUserById: function(p) {
			var params = {
				userid: "",
			};
			for(var i in p) {
				params[i] = p[i];
			}
			$.ajax({
				url: Model._URL_P + "/user/findUserById",
				type: "get",
				data: {
					"u.userid": params.userid
				},
				dataType: "json",
				async: false,
				success: function(result) {
					Model._RESULT = result;
				},
				error: function() {
					Model._RESULT = Common.pa._AJAX_JSON_ERR;
				}
			});
			return Model._RESULT;
		},
		findUserByName: function(p) {
			var params = {
				name: "",
			};
			for(var i in p) {
				params[i] = p[i];
			}
			$.ajax({
				url: Model._URL_P + "/user/findUserByName",
				type: "post",
				data: {
					"u.name": params.name
				},
				dataType: "json",
				async: false,
				success: function(result) {
					Model._RESULT = result;
				},
				error: function() {
					Model._RESULT = Common.pa._AJAX_JSON_ERR;
				}
			});
			return Model._RESULT;
		}

	}
}